package com.maixy.dailydemo.algorithm.audition;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName NumOfEle
 * @Description TODO
 * @Date 2021/3/2 10:34
 * @Author maixy
 */
public class NumOfEle {
    public static void main(String[] args) {
        Integer[] arr = new Integer[]{1, 2, 3, 4, 4, 1};

        Map<String, Integer> map = new HashMap<>();

        for (Integer integer : arr) {
            Integer num = map.get(String.valueOf(integer));
            map.put(String.valueOf(integer), num == null ? 1 : num + 1);
        }
        Set<Map.Entry<String, Integer>> set = map.entrySet();

        for (Map.Entry<String, Integer> entry : set) {
            System.out.println("单词 " + entry.getKey() + " 出现次数 : " + entry.getValue());
        }
    }

    public int removeDuplicates(int[] nums) {
        if (nums.length == 0)
            return 0;
        int i = 0;
        int j = 1;
        while (j < nums.length) {
            if (nums[i] == nums[j]) {
                j++;
            } else {
                i++;
                nums[i] = nums[j];
            }
        }
        return i += 1;
    }
}
